﻿<?php
$path = "../";
include_once($path.'configuration.php');

include_once($path.'head.php');

if(isset($_GET['action']))
	$action = $_GET['action'];
else
	$action='add';

if($action=="add"){
	if(isset($_POST) && isset($_POST['submit']) && $_POST['submit'] != ''){
		extract($_POST);
		if(isset($name) && $name != '' ){
			$user = new Salle($dbh);
			$user->setName($name);
			$user->save();
			header('Location: '.$path . 'administration/gestion_salle.php');
			exit;
		}else{
			$message = "Veuillez remplir tous les champs obligatoires !";
		}
	}
}elseif($action == "modif"){
	if(isset($_GET) && isset($_GET['salle']) && $_GET['salle'] != 0){
		if(isset($_POST) && isset($_POST['submit']) && $_POST['submit'] != ''){
			extract($_POST);
			if(isset($name) && $name != ''){
				$user = new Salle($dbh, $_GET['salle']);
				$user->setName($name);
				$user->save();
				header('Location: '.$path . 'administration/gestion_salle.php');
			}else{
				$message = "Veuillez remplir tous les champs obligatoires !";
			}
		}
	}
}elseif($action == "delete"){
	if(isset($_GET) && isset($_GET['salle']) && $_GET['salle'] != 0){
		$user = new salle($dbh, $_GET['salle']);
		$user->delete();
		header('Location: '.$path . 'administration/gestion_salle.php');
	}
}




if($action == "modif"){
	if(isset($_GET) && isset($_GET['salle']) && $_GET['salle'] != 0){
		$user = new Salle($dbh, $_GET['salle']);
		$name = $user->getName();
			
	}
}
?>
<div id="bodyWrapper">
	<script type="text/javascript">
	$(function() {
		$('#form').submit(function(){
			var error = false;
			var message = 'Erreur : <br/>';
			
			if($("#name").val() == ''){
				message += 'Choisissez un nom ! <br/>';
				$("#name").addClass( "error_input" )
				error = true;
			}else{
				$("#name").removeClass( "error_input" )
			}

			if(error == true){
				$("#dialog").html('<p>'+message+'</p>');
				$("#dialog").dialog("open");
				return false;
			}
		});
	});
	</script>
	<?php if(isset($message) && $message != ''){?>
	<script type="text/javascript" >
		$(function() {
			
			$("#modular_dialog").dialog({
				autoOpen: true,
				show: {
					effect: "explode",
					duration: 1000
				},
				hide: {
					effect: "explode",
					duration: 1000
				},
				modal: true
			});
			
		});
	</script>
	<div id="modular_dialog">
	<p><?php echo $message;?></p>
	</div>
	<?php } ?>
	<form method="post" id="form" action="">
		<p>
			<label for="name" class="label">Nom* :</label> <input type="text"
				id="name" name="name" class="input"
				value="<?php if(isset($name)) echo $name;?>" />
		</p>
		<p>
			<input type="submit" name="submit" id="submit" class="input"
				value="Envoyer" />
		</p>
		<a
				href="<?php echo $path; ?>administration/gestion_salle.php">Retour</a>
		
	</form>
</div>
<?php
include_once($path.'footer.php');
?>